package cn;

import java.sql.*;
import java.util.*;

public class MysqlTest4 {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
	    Connection con;
	    String sql, name, sex; 
	    int num, age;
		
	   try {
	      Class.forName("oracle.jdbc.odbc.JdbcOdbcDriver");
	   } catch(java.lang.ClassNotFoundException e) {
	       System.err.print("ClassNotFoundException: ");
	       System.err.println(e.getMessage());
	   }
	   try {
		   con = DriverManager.getConnection(url, "system", "system");
		   sql = "select * from student";
		   PreparedStatement stmt0= con.prepareStatement(sql);
		   ResultSet res = stmt0.executeQuery();
		   System.out.println("\n\n\n\n");
	       	System.out.println("年龄大于18的学生的信息表");
	       	System.out.println("-------------------------");
	       	System.out.println("学号    姓名    性别  年龄");  
           System.out.println("-------------------------");
		   while(res.next()) {
			   num = res.getInt(1);
			   name = res.getString(2);
			   sex = res.getString(3);
			   age = res.getInt(4);
			   if(age > 18) {
				   System.out.println(num+"    "+name+"   "+sex+"   "+age);
			   }
		   }
		   //关闭连接
		   try {
			   con.close();
			   stmt0.close();
		   } catch(Exception e) {
			   e.printStackTrace();
		   }
	   } catch(Exception e) {
		   e.printStackTrace();
	   }
	   in.close();
	}
}

